package com.woniu.woniu_bx.pojo;

import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * @author : 王泰元
 * @description: 封装响应信息的实体类，前后端分离的实现基础
 * @date : 2022/8/2 15:39
 */
@Data
public class ResponseEntity<T> {

    private Integer code;
    private String message;
    private T data;


    public ResponseEntity() {
    }

    public ResponseEntity(Integer code, String message) {
        this(code, message, null);
    }

    public ResponseEntity(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 操作成功的响应，200
    public static <T> ResponseEntity<T> SUCCESS(String message, T t) {
        return new ResponseEntity<>(HttpStatus.OK.value(), message, t);
    }

    // 没有权限的响应，403
    public static <T> ResponseEntity<T> NO_PERM(String message, T t) {
        return new ResponseEntity<>(HttpStatus.FORBIDDEN.value(), message, t);
    }

    // 系统错误（异常）的响应，500
    public static <T> ResponseEntity<T> FAIL(String message, T t) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), message, t);
    }

    // 登录失效（未认证），401
    public static <T> ResponseEntity<T> INVALID_TOKEN(String message, T t) {
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED.value(), message, t);
    }
    //余额不足 701
    public static <T> ResponseEntity<T> NO_MONEY(String message, T t) {
        return new ResponseEntity<>(701, message, t);
    }
}
